﻿using System.Windows;
using System.Windows.Input;
using IMClient.ViewModels;

namespace IMClient.View
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class RegisterWindow: Window
    {
        public RegisterWindow()
        {
            InitializeComponent();
            // 关键代码：设置 DataContext 为 RegisterViewModel 的实例
            DataContext = new RegisterViewModel();
            
            // 由于 PasswordBox 的特殊性，需要手动处理密码绑定
            PasswordBox.PasswordChanged += (s, e) =>
            {
                if (DataContext is RegisterViewModel vm)
                {
                    vm.Password = PasswordBox.Password;
                }
            };
        }

        private void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            LoginWindow loginWindow = new LoginWindow();
            loginWindow.Show();
            Close();
        }

        private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ButtonState == MouseButtonState.Pressed)
            {
                DragMove(); // 拖动窗口
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }
    }
}